package com.brush.common.enums;

import java.util.HashMap;
import java.util.Map;

/**
 *  规定http的请求方式
 */
public enum HttpMethod {
    GET,    HEAD,    POST,    PUT,    PATCH,    DELETE,    OPTIONS,    TRACE;

    //使用HashMap<String,HttpMethod>来存储对象
    private static final   Map<String,HttpMethod> mappings = new HashMap<String,HttpMethod>();

    /**
     * 静态构造函数
     */
    static {
        for (HttpMethod httpMethod : values()) {
            mappings.put(httpMethod.name(), httpMethod);
        }
    }

    public static HttpMethod resolve(String method) {
        return (method != null ? mappings.get(method) : null);
    }

    /**
     * 匹配是否支持这种枚举
     * @param method
     * @return
     */
    public static boolean matches(String method) {
        return (resolve(method) != null);
    }

}
